package com.guyuan.live_meeting.bean;

import com.google.gson.annotations.SerializedName;
import com.guyuan.live_meeting.entities.MeetingEntity;
import com.guyuan.live_meeting.utils.UmengUtils;

import java.util.Iterator;
import java.util.List;

public class MeetingBean {
    private String title;
    private String content;
    private StaffBean sendUser;
    private List<StaffBean> receivedUser;
    private long roomId;
    private long meetingId;//会议ID，申请关闭会议房间时用
    private long scheduleTime;
    /**
     *1：即时会议，2:预约会议（到了会议时间自动发起），3：预约会议（到了会议时间需要发起者手动发起）
     */
    private int meetingType;
    /**
     * {@link MeetingEntity#statusFlag}
     */
    private int statusFlag;
    public transient static final int STATUS_FLAG_ENDED = 0;
    public transient static final int STATUS_FLAG_ON_GOING = 1;
    public transient static final int STATUS_FLAG_APPOINTED = 2;
    public transient static final int MEETING_TYPE_INSTANT = 0;
    public transient static final int MEETING_TYPE_APPOINT_AUTO = 1;
    public transient static final int MEETING_TYPE_APPOINT_MANUAL = 2;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public StaffBean getSendUser() {
        return sendUser;
    }

    public void setSendUser(StaffBean sendUser) {
        this.sendUser = sendUser;
    }

    public List<StaffBean> getReceivedUser() {
        return receivedUser;
    }

    public void setReceivedUser(List<StaffBean> receivedUser) {
        this.receivedUser = receivedUser;
    }


    public long getRoomId() {
        return roomId;
    }

    public void setRoomId(long roomId) {
        this.roomId = roomId;
    }

    public long getMeetingId() {
        return meetingId;
    }

    public void setMeetingId(long meetingId) {
        this.meetingId = meetingId;
    }


    public long getScheduleTime() {
        return scheduleTime;
    }

    public void setScheduleTime(long scheduleTime) {
        this.scheduleTime = scheduleTime;
    }

    public int getMeetingType() {
        return meetingType;
    }

    public void setMeetingType(int meetingType) {
        this.meetingType = meetingType;
    }

    public int getStatusFlag() {
        return statusFlag;
    }

    public void setStatusFlag(int statusFlag) {
        this.statusFlag = statusFlag;
    }

    public MeetingEntity toMeetingEntity() {
        MeetingEntity entity = new MeetingEntity();
        entity.setTitle(getTitle());
        entity.setRoomId(getRoomId());
        entity.setContent(getContent());
        entity.setSendUser(UmengUtils.genUserAlias(getSendUser().getName(), getSendUser().getId()));
        entity.setMeetingTime((getScheduleTime()));
        entity.setMeetingType(getMeetingType());

        StringBuilder sb = new StringBuilder();
        if (!getReceivedUser().isEmpty()) {
            Iterator<StaffBean> iterator = getReceivedUser().iterator();
            while (iterator.hasNext()) {
                StaffBean next = iterator.next();
                sb.append(UmengUtils.genUserAlias(next.getName(), next.getId()));
                if (iterator.hasNext()) {
                    sb.append(",");
                }
            }
        }
        entity.setReceivedUsers(sb.toString());
        return entity;
    }

    public static MeetingBean convertFromEntity(MeetingEntity entity) throws Exception{
        MeetingBean meeting = new MeetingBean();
        meeting.setMeetingId(entity.getMeetingId());
        meeting.setTitle(entity.getTitle());
        meeting.setContent(entity.getContent());
        meeting.setRoomId(entity.getRoomId());
        meeting.setMeetingType(entity.getMeetingType());
        meeting.setScheduleTime(entity.getMeetingTime());
        meeting.setSendUser(UmengUtils.getStaffByUserAlias(entity.getSendUser()));
        meeting.setReceivedUser(UmengUtils.getReceiversByUserAliases(entity.getReceivedUsers()));
        meeting.setStatusFlag(entity.getStatusFlag());
        return meeting;
    }

    @Override
    public String toString() {
        return "MeetingBean{" +
                "title='" + title + '\'' +
                ", content='" + content + '\'' +
                ", sendUser=" + sendUser +
                ", receivedUser=" + receivedUser +
                ", roomId=" + roomId +
                ", meetingId=" + meetingId +
                ", scheduleTime=" + scheduleTime +
                ", meetingType=" + meetingType +
                ", statusFlag=" + statusFlag +
                '}';
    }
}
